//app.js
var wh = require("utils/wh.js");
App({
  // 微信登录
  wlogin: function (userInfo) {
    let that = this;
    wx.getExtConfig({
      success: function (res) {
        module.exports.globalData = res.extConfig;
        //进行微信登录
        wx.login({
          success: function (res) {
            if (res.code) {
              let data = { code: res.code, encryptedData: userInfo.encryptedData, iv: userInfo.iv, rawData: userInfo.rawData, signature: userInfo.signature };
              wh.Post('/api/user/login', data, function (info) {//登录成功返回的信息
                let userinfo = JSON.stringify(info);
                wx.setStorageSync('W_Userinfo', userinfo);//存储
                wx.setStorageSync('employId', info.id);
                wx.setStorageSync('whlw_app_id', module.exports.globalData.app_id);
                //由于这里是网络请求，可能会在 Page.onLoad 之后才返回 所以此处加入 callback 以防止这种情况
                if (that.employIdCallback) {
                  that.employIdCallback(info.id);
                }
                return true;
              });
            }
          },
          fail: function () {
            return false;
          }
        })
      }
    });
  }
});
